package com.czxy.changgou4.service.impl;

import com.czxy.changgou4.domain.AuthUser;
import com.czxy.changgou4.feign.UserFeign;
import com.czxy.changgou4.service.AuthService;
import com.czxy.changgou4.utils.BCrypt;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 桐叔
 * @email liangtong@itcast.cn
 */
@Service
public class AuthServiceImpl implements AuthService {
    @Resource
    private UserFeign userFeign;

    @Override
    public AuthUser login(AuthUser authUser) {
        //1 通过用户名查询
        AuthUser findAuthUser = userFeign.findByUsername(authUser);
        if(authUser == null) {
            return null;        //用户名不对
        }

        //2 校验密码
        boolean checkpw = BCrypt.checkpw(authUser.getPassword(), findAuthUser.getPassword());
        if(checkpw) {
            return findAuthUser;
        }
        return null;        //密码不对
    }
}
